function drag(o, s,inset)
{
    var x = 0;
    var y = 0;
    var MoveStart = false;
    var CurrentPosX = 0;
    var CurrentPosY = 0;
    var CurrentPosTime = 0;
    if (typeof o == "string") o = document.getElementById(o);
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
    o.orig_index = o.style.zIndex;
    o.onmousedown = function()
    {

        var a = getEvent();;
        var evSrc = a.srcElement ? a.srcElement : a.target;
        if (evSrc.id == "popclose") {//点击的是关闭按钮
            return;
        }
        if(!inset){//对于独立式，需要屏蔽层
            this.style.zIndex = 4000;
            document.getElementById("hidediv").style.display = "block";
        }
        x = a.clientX + document.body.scrollLeft - o.offsetLeft;
        y = a.clientY + document.body.scrollTop - o.offsetTop;
        MoveStart = true;
        CurrentPosX = a.clientX;
        CurrentPosY = a.clientY;
        CurrentPosTime = new Date().getMilliseconds();
    }

    o.onmouseup = function()
    {
        if (!MoveStart) return;
        this.style.zIndex = o.orig_index;
        MoveStart = false;
        CurrentPosX = 0;
        CurrentPosY = 0;
        CurrentPosTime = 0;
        document.getElementById("hidediv").style.display = "none";
    }

    document.onmousemove = function() {
        if (!MoveStart) return;
        var a =getEvent();
        if (Math.abs(a.clientX - CurrentPosX) > 20 || Math.abs(a.clientY - CurrentPosY) > 20 || Math.abs(new Date().getMilliseconds() - CurrentPosTime) > 100) {
            o.style.left = a.clientX + document.body.scrollLeft - x;
            o.style.top = a.clientY + document.body.scrollTop - y;
            o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
            o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
            CurrentPosX = a.clientX;
            CurrentPosY = a.clientY;
            CurrentPosTime = new Date().getMilliseconds();
        }
    }


    if (s == 1)
    {
        var orig_scroll = window.onscroll ? window.onscroll : function () {
        };
        window.onscroll = function ()
        {
            orig_scroll();
            o.style.left = o.orig_x + document.body.scrollLeft;
            o.style.top = o.orig_y + document.body.scrollTop;
        }
    }
}

function showPopupDiv() {
    var id = "movediv";
    document.getElementById(id).style.display = "block";
    document.getElementById("popbgdiv").style.display = "block";
    var evt=getEvent();
    if (getBrowserType() == "fox")
    {
        document.getElementById(id).style.left = evt.pageX + 10;
        document.getElementById(id).style.top = evt.pageY + 10;
    }
    else {
        document.getElementById(id).style.left = evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft) + 10;
        document.getElementById(id).style.top = evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + 10;
    }

}
function hidePopupDiv() {
    document.getElementById("movediv").style.display = "none";
    document.getElementById("popbgdiv").style.display = "none";
}


function initPopDiv(inset) {
    var popupdiv=document.getElementById("popupdiv");
    if(popupdiv!=null){
        if(inset){//嵌入式
               var insetdiv=document.getElementById("insetdiv");
               if(insetdiv!=null) return;
               else{
                     document.getElementsByTagName("BODY")[0].removeChild(popupdiv);
               }

        }else{//独立式
               var innerframe=document.getElementById("innerframe");
               if(innerframe!=null) return;
               else{
                   document.getElementsByTagName("BODY")[0].removeChild(popupdiv);
               }
        }
    }
    var divstr = '<div id="movediv" style="left:20px;top:20px;display:none;cursor:move;BORDER-RIGHT: 2pt solid  #336699; BORDER-TOP: 0pt ridge #9ad452; BORDER-LEFT: 0pt solid  #9ad452; BORDER-BOTTOM: 2pt solid #336699;z-index:4000;">' +
                 ' <table width="100%" border="0" cellpadding="5" cellspacing="1" class="list_block_table"><tr align="right" class="list_block_table_head"><td align="right"><a href="javascript:hidePopupDiv()"><img id="popclose" src="img/close1414.gif"/></a></td></tr></table>' +
                 '<div id="contentdiv">' +
                 '<iframe name="innerframe" id="innerframe" style="width:100%;height:92%;border:0;" frameborder=0></iframe>' +
                 '</div></div>';
    if(inset){
         divstr = '<div id="movediv" style="left:20px;top:20px;display:none;cursor:move;BORDER-RIGHT: 2pt solid  #336699; BORDER-TOP: 0pt ridge #9ad452; BORDER-LEFT: 0pt solid  #9ad452; BORDER-BOTTOM: 2pt solid #336699;z-index:4000;">' +
                 ' <table width="100%" border="0" cellpadding="5" cellspacing="1" class="list_block_table"><tr align="right" class="list_block_table_head"><td align="right"><a href="javascript:hidePopupDiv()"><img id="popclose" src="img/close1414.gif"/></a></td></tr></table>' +
                 '<div id="contentdiv">' +
                 '<div id="insetdiv" style="width:100%;height:92%"></div>' +
                 '</div></div>';
    }

        var div = document.createElement("div");
        div.id="popupdiv";
        document.getElementsByTagName("BODY")[0].appendChild(div);
        div.innerHTML = divstr;

        var subBgObj = document.createElement("div");//创建一个背景层，覆盖iframe
        subBgObj.setAttribute("id", "hidediv");
        subBgObj.style.position = "absolute";
        subBgObj.style.top = "0";
        subBgObj.style.background = "#777";
        subBgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0,finishOpacity=0";
        subBgObj.style.opacity = "0";
        subBgObj.style.left = "0";
        subBgObj.style.width = "100%";
        subBgObj.style.height = "100%";
        subBgObj.style.zIndex = "5000";
        subBgObj.style.display = "none";
        document.getElementById("contentdiv").appendChild(subBgObj);


        var sWidth,sHeight;
        sWidth = document.body.offsetWidth;//浏览器工作区域内页面宽度
        sHeight = screen.height;//屏幕高度（垂直分辨率）
        var bgObj = document.createElement("div");//创建一个背景层，覆盖body
        // <div   id="bgDiv"   style="position:absolute;   top:0;   background-color:#777;   filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);   opacity:0.6;   left:0;   width:918px;   height:768px;   z-index:10000;"> </div>
        bgObj.setAttribute("id", "popbgdiv");
        bgObj.style.position = "absolute";
        bgObj.style.top = "0";
        bgObj.style.background = "#777";
        bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
        bgObj.style.opacity = "0.6";
        bgObj.style.left = "0";
        bgObj.style.width = sWidth + "px";
        bgObj.style.height = sHeight + "px";
        bgObj.style.zIndex = "3000";
        bgObj.style.display = "none";
        document.getElementsByTagName("BODY")[0].appendChild(bgObj);
        if(inset){
        drag("movediv",0,true);
        } else{
               drag("movediv", 0,false);
        }
}

function _SelectPop(url0, callback) {
    var link = '&';
    if (url0.indexOf('?') == -1) {
        link = "?";
    }
    var url = url0 + link + "callback=" + getFunctionName(callback) + "&rnd=" + getRandomNum();
    window.open(url, "innerframe");
}
function popup(url0, callback){
    initPopDiv(false);
     showPopupDiv();
     _SelectPop(url0, callback);
}
function popup_inset(html,isURL){
     if(isURL){//是网址
           ajax(html,function(data){
               popup_inset(data,false);
           },false,"get",null,1,"");
           return;
     }
     initPopDiv(true);
     showPopupDiv();
     document.getElementById("insetdiv").innerHTML=html;
}

